package com.example.mysqlview;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {
    private EditText et_id,et_name,et_price;
    private Button bt_tj;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        et_id = findViewById(R.id.et_id);
        et_name = findViewById(R.id.et_name);
        et_price = findViewById(R.id.et_price);
        bt_tj = findViewById(R.id.bt_tj);

        bt_tj.setOnClickListener(view -> {
            String id = et_id.getText().toString();
            String name = et_name.getText().toString();
            int price = Integer.parseInt(et_price.getText().toString());

            MySQLiteOpenHelper helper = new MySQLiteOpenHelper(AddActivity.this,"fru.db",null,1);
            SQLiteDatabase writebleDatabase = helper.getWritableDatabase();

            ContentValues values = new ContentValues();
            values.put("id",id);
            values.put("name",name);
            values.put("price",price);

            writebleDatabase.insert("fruit",null,values);
            writebleDatabase.close();

            finish();
        });
    }
}